//
//  ACTestViewController.m
//  LFUCache_Example
//
//  Created by autohome on 2021/8/16.
//  Copyright © 2021 caixiang305621856. All rights reserved.
//

#import "ACTestViewController.h"

@interface Test : NSObject

@end

@implementation Test
- (void)dealloc {
    NSLog(@"%s",__func__);
    NSLog(@"%@",[NSThread currentThread]);
}
@end
@interface ACTestViewController ()
{
    CFMutableDictionaryRef _map ;
}
@end

@implementation ACTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    _map = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFDictionarySetValue(_map, (__bridge const void *)(@"key"), (__bridge const void*)([Test new]));
}

- (void)remove {
    if (CFDictionaryGetCount(_map) > 0) {
        CFMutableDictionaryRef holder = _map;
        _map = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
            CFRelease(holder); // hold and release in specified queue
        });
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self remove];
}
- (void)dealloc {
    CFRelease(_map);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
